package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据用户Id获得购物车信息
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{currentId} and name =#{dishName}")
    ShoppingCart getByUserIdAndName(Long currentId, String dishName);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    void insert(ShoppingCart shoppingCart);

    /**
     * 更新购物车数据
     * @param shoppingCart
     */
    void update(ShoppingCart shoppingCart);

    /**
     * 查询购物车数据
     * @param shoppingCart
     */
    List<ShoppingCart> select(ShoppingCart shoppingCart);

    /**
     * 更新number字段
     * @param cart
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 根据用户id获得购物车数据
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{currentId}")
    List<ShoppingCart> getByUserId(Long currentId);

    /**
     * 根据用户id清空购物车数据
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id=#{currentId}")
    void deleteByUserId(Long currentId);

    /**
     * 删除购物车中的一个商品
     * @param shoppingCart
     */
    void delete(ShoppingCart shoppingCart);
}
